Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tailcall-prettier #1731

Merged
merged 15 commits into from
Apr 16, 2024
Merged

chore: add tailcall-prettier #1731

merged 15 commits into from
Apr 16, 2024

Conversation

ssddOnTop
Copy link
Member

@ssddOnTop ssddOnTop commented Apr 15, 2024

Summary:
Briefly describe the changes made in this PR.

Issue Reference(s):
Fixes #1730
/claim 1730

Build & Testing:

  • I ran cargo test successfully.
  • I have run ./lint.sh --mode=fix to fix all linting issues raised by ./lint.sh --mode=check.

Checklist:

  • I have added relevant unit & integration tests.
  • I have updated the documentation accordingly.
  • I have performed a self-review of my code.
  • PR follows the naming convention of <type>(<optional scope>): <title>

Summary by CodeRabbit

  • New Features
    • Introduced code formatting functionality using Prettier for specified file types.
    • Added a parser module to detect file types based on extensions.
    • Implemented asynchronous formatting using Tokio for improved performance.
  • Tests
    • Included a test for formatting JavaScript code.
  • Chores
    • Updated CI workflow to install Node.js, Prettier, and configure npm global path.

Copy link
Contributor

coderabbitai bot commented Apr 15, 2024

Walkthrough

Walkthrough

The changes involve the creation of the tailcall-prettier workspace, which integrates a Rust-based API to format code using the Prettier tool. This setup includes modifications to the project's Cargo configuration, the addition of new modules for formatting and parsing logic, and the inclusion of functionality to detect and format various file types using Prettier.

Changes

File Path Change Summary
tailcall-prettier/Cargo.toml Specifies dependencies for tailcall-prettier, including anyhow, lazy_static, strum_macros, and sets tokio.workspace to true.
tailcall-prettier/src/lib.rs Introduces a format function to format code using Prettier based on file type, includes JavaScript code formatting test.
tailcall-prettier/src/parser.rs Adds a parser module with Parser enum to detect file types based on extensions and a detect method to determine file type.
tailcall-prettier/src/prettier.rs Includes a Prettier struct with a format method using Tokio for asynchronous operations to run Prettier on source code.
.github/workflows/ci.yml Adds steps to install Node.js, Prettier, and configure npm global path in GitHub Actions workflow.
tests/execution_spec.rs Involves formatting identity and content using tailcall_prettier::format before equality check with pretty_assertions::assert_eq.

Assessment against linked issues

Objective Addressed Explanation
Create a new workspace called tailcall-prettier (#1730)
Tailcall prettier provides a Rust based programmable API that takes in content and formats it using Prettier (#1730)
Read files in Rust and pipe them to Prettier (#1730)
Ensure the local version of Prettier is used (#1730) It's not explicitly stated if the local version of Prettier is enforced.
Execution should be fast and multithreaded if required (#1730) There is no mention of multithreading implementation for faster execution.

The implementation aligns with most of the specified requirements. However, clarification on enforcing the use of the local Prettier version and implementing multithreading for faster execution is needed to fully meet the objectives.


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c6a30ad and 79aef83.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (5)
  • tailcall-prettier/Cargo.toml (1 hunks)
  • tailcall-prettier/src/lib.rs (1 hunks)
  • tailcall-prettier/src/parser.rs (1 hunks)
  • tailcall-prettier/src/prettier.rs (1 hunks)
  • tests/execution_spec.rs (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • tailcall-prettier/Cargo.toml
  • tailcall-prettier/src/lib.rs
  • tests/execution_spec.rs
Additional Context Used
Path-based Instructions (2)
tailcall-prettier/src/parser.rs (1)

Pattern **/*.rs: Programming Style Guidelines

  • When calling functions that do not need to modify values, pass references of those values.
  • When calling functions that need to modify values, pass ownership of the values, and ensure they are returned from the function.

IMPORTANT: This programming style may not be suitable for performance-sensitive components or hot code paths. In such cases, prioritize efficiency and optimization strategies to enhance performance.

Testing

  1. Write Tests: For every new feature or bugfix, ensure that you write appropriate tests.
    Structure your tests in the following way:

    use pretty_assertions::assert_eq;
    fn test_something_important() {
       let value = setup_something_using_a_function();
    
       let actual = perform_some_operation_on_the_value(value);
       let expected = ExpectedValue {foo: 1, bar: 2};
    
       assert_eq!(actual, expected);
    }
    • Setup the value using helper methods in tests.
    • Create an actual and an expected value.
    • Assert the two values in a new line.
    • Ensure there are only one assertions per test.
tailcall-prettier/src/prettier.rs (1)

Pattern **/*.rs: Programming Style Guidelines

  • When calling functions that do not need to modify values, pass references of those values.
  • When calling functions that need to modify values, pass ownership of the values, and ensure they are returned from the function.

IMPORTANT: This programming style may not be suitable for performance-sensitive components or hot code paths. In such cases, prioritize efficiency and optimization strategies to enhance performance.

Testing

  1. Write Tests: For every new feature or bugfix, ensure that you write appropriate tests.
    Structure your tests in the following way:

    use pretty_assertions::assert_eq;
    fn test_something_important() {
       let value = setup_something_using_a_function();
    
       let actual = perform_some_operation_on_the_value(value);
       let expected = ExpectedValue {foo: 1, bar: 2};
    
       assert_eq!(actual, expected);
    }
    • Setup the value using helper methods in tests.
    • Create an actual and an expected value.
    • Assert the two values in a new line.
    • Ensure there are only one assertions per test.
Additional comments not posted (4)
tailcall-prettier/src/parser.rs (2)

3-11: Enum Parser correctly defines various file types and uses strum_macros::Display for string representation.


13-29: Method detect correctly identifies the parser based on file extensions. Consider handling potential panics from unwrap more gracefully.

tailcall-prettier/src/prettier.rs (2)

8-20: Struct Prettier correctly initializes a multi-threaded Tokio runtime suitable for handling blocking operations.


22-45: Method format correctly handles formatting operations in a non-blocking manner. Consider including error details from output.stderr in the error message for better debugging.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Apr 15, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

tests/execution_spec.rs Outdated Show resolved Hide resolved
@tusharmath tusharmath changed the title feat: tailcall prettier chore: add `tailcall-prettier' Apr 15, 2024
@github-actions github-actions bot added the type: chore Routine tasks like conversions, reorganization, and maintenance work. label Apr 15, 2024
@tusharmath tusharmath changed the title chore: add `tailcall-prettier' chore: add tailcall-prettier Apr 15, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

tailcall-prettier/src/lib.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 88.46154% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 87.14%. Comparing base (c587c4a) to head (79aef83).
Report is 2 commits behind head on main.

Files Patch % Lines
tailcall-prettier/src/parser.rs 81.25% 3 Missing ⚠️
tailcall-prettier/src/prettier.rs 90.90% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1731      +/-   ##
==========================================
- Coverage   87.19%   87.14%   -0.06%     
==========================================
  Files         149      153       +4     
  Lines       15457    15599     +142     
==========================================
+ Hits        13477    13593     +116     
- Misses       1980     2006      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ssddOnTop ssddOnTop added ci: lint Automatically fix the linters issues and make a commit and removed ci: lint Automatically fix the linters issues and make a commit labels Apr 15, 2024
@tusharmath tusharmath merged commit 69f22a6 into main Apr 16, 2024
30 of 31 checks passed
@tusharmath tusharmath deleted the feat/tc-prettier branch April 16, 2024 06:02
ssddOnTop added a commit that referenced this pull request May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 Bounty claim type: chore Routine tasks like conversions, reorganization, and maintenance work. type: feature Brand new functionality, features, pages, workflows, endpoints, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore: Create a tailcall-prettier
2 participants